package com.dangz.dans.dao;

import com.dangz.dans.model.ClientInfo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author dangz
 * @since 2018/6/25 15:35
 */
@Repository
public interface ClientInfoRepository extends CrudRepository<ClientInfo, String> {
    ClientInfo findByClientId(String clientId);
    List<ClientInfo> findAllByUserId(String userId);
    @Modifying
    @Transactional
    void deleteByClientId(String clientId);

    @Query("SELECT clientId, userId, connected, mostSignbits, lastConnectedDate FROM ClientInfo GROUP BY userId")
    List<ClientInfo> findAllByGreoupByUserId();
}
